import { request } from 'umi';

export function fetchDataMap(importInfo: API.ImportInfo) {
  const data = new FormData();
  data.append('dataImport', JSON.stringify(importInfo));
  return request<API.DataMapInfo>(`/api/DataMap`, {
    method: 'POST',
    body: data,
  });
}

export function deleteUploadFile(fileName: string) {
  return request(`/api/Upload/Delete/${fileName}`, {
    method: 'POST',
  });
}
export function downLoadTemplate(fileName: string) {
  return request(`/api/restricted/DataImport/Down/${fileName}`, {
    method: 'POST',
    getResponse: true,
    responseType: 'blob',
  });
}
export function dataImport(
  importInfo: API.ImportInfo,
  ignoreErr: string,
  errorDatas: object[],
  dataMaps: object[],
  isNewMap: boolean,
) {
  const data = new FormData();
  data.append('dataImport', JSON.stringify(importInfo));
  data.append('ignoreErr', ignoreErr ? 'true' : 'false');
  data.append('errorDatas', JSON.stringify(errorDatas));
  if (dataMaps) {
    data.append('dataMaps', JSON.stringify(dataMaps));
  }
  data.append('isNewMap', isNewMap ? 'true' : 'false');
  return request(`/api/restricted/DataImport`, {
    method: 'POST',
    body: data,
  });
}

export function dataProgress(fileName: string) {
  const data = new FormData();
  data.append('fileName', fileName);
  return request<API.ImportProgress>(`/api/DataImportProcess`, {
    method: 'POST',
    body: data,
  });
}
